﻿using System;
using System.Collections.Generic;
using System.Xml.Linq;
using Game;

namespace Test1
{
    public class Test1TextDialog : Dialog
    {
        public ButtonWidget m_okButton;

        public ButtonWidget m_cancelButton;

        public List<Widget> Extra = new List<Widget>();

        public Action OnYesClicked;

        public StackPanelWidget Stack;

        public Test1TextDialog(string title, string txt, Action action)
        {
            XElement node = ContentManager.Get<XElement>("Test1/Dialogs/Test1TextDialog");
            LoadContents(this, node);
            Stack = Children.Find<StackPanelWidget>("Stack");
            m_okButton = Children.Find<ButtonWidget>("OkButton");
            m_cancelButton = Children.Find<ButtonWidget>("CancelButton");
            LabelWidget labelWidget = Children.Find<LabelWidget>("Text");
            LabelWidget labelWidget2 = Children.Find<LabelWidget>("Title");
            labelWidget.Text = txt;
            labelWidget2.Text = title;
            OnYesClicked = (Action)Delegate.Combine(OnYesClicked, action);
            m_okButton.IsVisible = action != null;
        }

        public override void Update()
        {
            if (m_okButton.IsClicked)
            {
                DialogsManager.HideDialog(this);
                OnYesClicked();
            }

            if (m_cancelButton.IsClicked || base.Input.Cancel)
            {
                DialogsManager.HideDialog(this);
            }
        }
    }
}